<!DOCTYPE HTML>
<html>
  <head>
    <title>file upload</title>
  </head>
   
  <body>
  	<div>
	<input type="hidden" name = "userId">
	<input type="text" id="userName" name="userName">
	<input type="password" id="password" name="password">
	<input type="button" id="createBtn" value="创建">
	
	<input type="button" id="updateBtn" value="修改">
	<input type="button" id="getBtn" value="查询">
	<input type="button" id="deleteBtn" value="删除">
  	</div>
  	
  	<div>
  		注册
  		<input type="text" id="regist_userName">
  		<input type="password" id="regist_password">
  		<input type="button" id="regist_simplebtn" value="simple register">
  		<input type="button" id="regist_btn" value="register">
  	</div>
  	
	<script type="text/javascript">
	var contextPath = "/rest/sso";
	createBtn.onclick = function(){
		var req = new XMLHttpRequest();
		req.open("POST", contextPath+"/user");
		req.setRequestHeader("Content-Type","application/json; charSet=UTF-8");
		
		req.onreadystatechange = function(){
		   if(this.status == 4){
		     console.log(this.response);
		   }
		}
		//req.setRequestHeader("Content-Type","application/json; charset=UTF-8");
		//req.send(JSON.stringify({"buildingId":"1"}));
		req.send(JSON.stringify({"userName":userName.value,"password":password.value}));
	}
	updateBtn.onclick = function(){
		var req = new XMLHttpRequest();
		req.open("PUT", contextPath+"/user/"+userId.value);
		req.setRequestHeader("Content-Type","application/json; charSet=UTF-8");
		
		req.onreadystatechange = function(){
		   if(this.status == 4){
		     console.log(this.response);
		   }
		}
		//req.setRequestHeader("Content-Type","application/json; charset=UTF-8");
		//req.send(JSON.stringify({"buildingId":"1"}));
		req.send(JSON.stringify({"userName":userName.value,"password":password.value}));
	}
	getBtn.onclick = function(){
		var req = new XMLHttpRequest();
		req.open("GET", contextPath+"/user");
		req.setRequestHeader("Content-Type","application/json; charSet=UTF-8");
		
		req.onreadystatechange = function(){
		   if(this.status == 4){
		     console.log(this.response);
		   }
		}
		//req.setRequestHeader("Content-Type","application/json; charset=UTF-8");
		//req.send(JSON.stringify({"buildingId":"1"}));
		req.send(JSON.stringify({"userName":userName.value,"password":password.value}));
	}
	deleteBtn.onclick = function(){
		var req = new XMLHttpRequest();
		req.open("DELETE", contextPath+"/user");
		req.onreadystatechange = function(){
		   if(this.status == 4){
		     console.log(this.response);
		   }
		}
		//req.setRequestHeader("Content-Type","application/json; charset=UTF-8");
		//req.send(JSON.stringify({"buildingId":"1"}));
		req.send(JSON.stringify({"userName":userName.value,"password":password.value}));
	}

	regist_simplebtn.onclick = function(){
		var req = new XMLHttpRequest();
		req.open("POST", "/rest/sso/register");
		req.onreadystatechange = function(){
		   if(this.status == 4){
		     console.log(this.response);
		   }
		}
		req.setRequestHeader("Content-Type","application/json; charset=UTF-8");
		req.send(JSON.stringify({
			"userName":regist_userName.value,
			"password":regist_password.value,
			"roles":[{"roleCode":"customer"}]
		}));
	}
	
	regist_btn.onclick = function(){
		var req = new XMLHttpRequest();
		req.open("POST", "/rest/mysen/register/customer");
		req.onreadystatechange = function(){
		   if(this.status == 4){
		     console.log(this.response);
		   }
		}
		req.setRequestHeader("Content-Type","application/json; charset=UTF-8");
		req.send(JSON.stringify({
			"userName":regist_userName.value,
			"password":regist_password.value,
			"userImage":"image",
			"userType":"1",
			"userPhone":"13112341234"
		}));
	}
	</script>
  </body>
</html>